TARGET1 = server
TARGET2 = client
CC = gcc
CFLAGS += -pthread
CFLAGS += -I../../include

CLIENTPATH := ./src/client
SERVERPATH := ./src/server

BUILD = build
OBJS = $(BUILD)/objs
BIN = $(BUILD)/bin

SERVERSRC = $(foreach dir, $(SERVERPATH), $(wildcard $(dir)/*.c))
CLIENTSRC = $(foreach dir, $(CLIENTPATH), $(wildcard $(dir)/*.c))
SERVEROBJS = $(patsubst %.c, $(OBJS)/%.o, $(notdir $(SERVERSRC)))
CLIENTOBJS = $(patsubst %.c, $(OBJS)/%.o, $(notdir $(CLIENTSRC)))

VPATH = $(CLIENTPATH) : $(SERVERPATH)

all: $(BUILD) $(OBJS) $(BIN) $(TARGET1) $(TARGET2)
.PHONY:all clean install
$(TARGET1) : $(SERVEROBJS)
	$(CC) $^ -o $@ $(CFLAGS)
$(TARGET2) : $(CLIENTOBJS)
	$(CC) $^ -o $@ $(CFLAGS)

$(OBJS)/%.o : $(SERVERPATH)/%.c 	
	$(CC) -c $< -o $@ $(CFLAGS)
$(OBJS)/%.o : $(CLIENTPATH)/%.c
	$(CC) -c $< -o $@ $(CFLAGS)

$(BUILD):
	mkdir -p $(BUILD)
$(OBJS):
	mkdir -p $(OBJS)
$(BIN):
	mkdir -p $(BIN)

clean:
	$(RM) $(OBJS)/*.o server client -r
install:
	mv $(TARGET1) $(TARGET2) ./build/bin
